﻿
@{
    ViewBag.Title = "注册";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="layui-row">
    <div class="layui-col-md4">
        <div style="width:100%;opacity: 0;">
            W
        </div>
    </div>
    <div class="layui-col-md4">
        <div style="width:100%;padding:160px 0px;">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;text-align:center;">
                <legend>用户注册</legend>
            </fieldset>
            <form class="layui-form">
                <div class="layui-form-item">
                    <div class="">
                        <input type="text" id="email" name="email" maxlength="50" required lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="">
                        <input type="password" id="pwd" maxlength="30" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="">
                        <input type="password" id="pwd_1" maxlength="30" name="password_1" required lay-verify="required" placeholder="请输入确认密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="">
                        <input type="text" id="u_name" name="u_name" maxlength="50" required lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <div class="">
                        <input type="checkbox" name="remaber_me" lay-skin="primary" title="《同意用户协议》" checked="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="">
                        <button type="button" class="layui-btn" style="width:100%;" onclick="login()">立即注册</button>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="">
                        <a href="/Home/Login" class="" style="color:green;float:right;">已有账号？立即登录</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-col-md4" style="">
        <div style="width:100%;opacity: 0;">
            W
        </div>
    </div>
</div>

<script>
    function login() {
        if ($("#email").val() == "") {
            layer.alert('请输入账号');
            return;
        }
        if ($("#pwd").val() == "") {
            layer.alert('请输入密码');
            return;
        }
        if ($("#pwd_1").val() == "") {
            layer.alert('请输入确认密码');
            return;
        }
        if ($("#pwd").val() != $("#pwd_1").val()) {
            layer.alert('两次密码不一致');
            return;
        }
        if ($("#u_name").val() == "") {
            layer.alert('请输入昵称');
            return;
        }

        var email = $("#email").val();
        var pwd = $("#pwd").val();
        var u_name = $("#u_name").val();
        if (email.indexOf('script') != -1 || pwd.indexOf('script') != -1 || u_name.indexOf('script') != -1) {
            layer.alert('script不能作为提交的数据，请使用其他值替换');
            return;
        }

        layer.load(1);
        $.ajax({
            url: '/Home/Register',
            type: 'POST',
            data: {
                email: email,
                password: pwd,
                u_name: u_name
            },
            dataType: 'text',
            success: function (data) {
                layer.closeAll('loading');
                if (data == "1") {
                    layer.alert("注册成功", function () {
                        location.href = "/Home/Login";
                    });
                 
                } else {
                    layer.alert(data);
                }
            }
        });
    }
</script>
